package huawei;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 连续字母长度
 */
public class Q23 {

    // 计算阶乘
    public static int f(int n) {
        int r = 1;
        for (int i = 1; i <= n; i++) {
            r *= i;
        }
        return r;
    }

    public static String getPermutation(int n, int k) {
        List<Integer> list = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            list.add(i);
        }
        k -= 1;

        StringBuilder sb = new StringBuilder();
        for (int i = n - 1; i >= 0; i--) {
            int index = k / f(i);
            k = k % f(i);
            sb.append(list.get(index));
            list.remove(index);
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 读取输入n和k
        int n = scanner.nextInt();
        int k = scanner.nextInt();

        // 输出第k个排列
        System.out.println(getPermutation(n, k));

        scanner.close();

    }


}
